package com.project.logistics.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.logistics.bean.Repairs;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by94988 on 2021/3/19 16:48
 */
@Mapper
public interface RepairsMapper extends BaseMapper<Repairs> {
    @Select("select * from repairs where repairs_status = 1")
    List<Repairs> getUndealrepairs();

    @Select("select * from repairs where repairs_id = #{id}")
    Repairs getRepairById(int id);

    @Update("update repairs set service_user_id = #{serviceUserId} ,repairs_status = 2 where repairs_id = #{repairsId}")
    int setRepairman(@Param("serviceUserId") String serviceUserId,@Param("repairsId") int repairsId);

    @Delete("delete from repairs where repairs_id = #{repairsId}")
    int deleteRepairs(int repairsId);

    //查看全部用户repairs表
    @Select("select * from repairs ")
    List<Repairs> getAllRepairs();

    @Select("select * from repairs where repairs_status = 2")
    List<Repairs> getAllUnRepairs();

    @Select("select * from repairs where repairs_status = 3 ")
    List<Repairs> getAllDealRepairs();

    //查看报修Id详细报修情况
    @Select("select * from repairs where repairs_id=#{repairsId}")
    Repairs getRepair(int repairsId);

    //查看当前报修人报修单
    @Select("select * from repairs where repairs_user_id=#{repairs_user_id}")
    List<Repairs> getRepairsByUserId(String userId);

    //查看当前维修人报修单
    @Select("select * from repairs where service_user_id=#{service_user_id}")
    List<Repairs> getRepairsByRepairsmanId(String repairsmanId);

    //添加当前用户报修
    @Insert("insert into repairs(`repairs_time`,`repairs_user_id`,`repairs_place`,`repairs_telephone`,`repairs_photo`,`repairs_detail`,`repairs_status`,`repair_kind`) values(#{repairsTime},#{repairsUserId},#{repairsPlace},#{repairsTelephone},#{repairsPhoto},#{repairsDetail},#{repairsStatus},#{repairKind})")
    void insertRepairs(Repairs repairs);

    //修改当前报修单
    @Update("update repairs set repair_kind=#{repairsKind},repairs_telephone=#{repairsTelephone},repairs_place=#{repairsPlace},repairs_detail=#{repairsDetail},repairs_photo=#{repairsPhoto} where repairs_id=#{repairsId}")
    void updateRepairs(Repairs repairs);

    //修改当前报修单当前报修情况
    @Update("update repairs set repairs_status=#{repairsStatus} where repairs_id=#{repairsId}")
    void updateRepairsStatus(@Param("repairsStatus") int repairsStatus,@Param("repairsId") int repairsId);
    //查看当前维修人报修单
//    @Select("select * from repairs where service_user_id=#{repairsmanId} and repairs_status=#{repairsStatus}")
//    List<Repairs> getRepairsByRepairsmanIdAndStatus(@Param("repairsmanId") String repairsmanId,@Param("repairsStatus") int repairsStatus);

    List<Repairs> getRepairsByRepairsmanIdAndStatus(@Param("repairsmanId")String repairsmanId,@Param("repairsStatus")int repairsStatus);



}
